added Feb 2001 SDK
[windows-sources.git] / shared source / sscli20 / jscript / engine / lenientglobalobject.cs
blob5e8b46db5353fd0f46986574c2b2eed446e0d251
1 // ==++==
2 //
3 //
4 // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
5 //
6 // The use and distribution terms for this software are contained in the file
7 // named license.txt, which can be found in the root of this distribution.
8 // By using this software in any fashion, you are agreeing to be bound by the
9 // terms of this license.
10 //
11 // You must not remove this notice, or any other, from this software.
12 //
13 //
14 // ==--==
16 namespace Microsoft.JScript {
18 using Microsoft.JScript.Vsa;
19 using System;
20 using System.Reflection;
21 using System.Collections;
23 public sealed class LenientGlobalObject : GlobalObject{
24 // properties
25 public new Object Infinity;
26 private Object MathField;
27 public new Object NaN;
28 public new Object undefined;
29 // backing fields for constructor properties
30 private Object ActiveXObjectField;
31 private Object ArrayField;
32 private Object BooleanField;
33 private Object DateField;
34 private Object EnumeratorField;
35 private Object ErrorField;
36 private Object EvalErrorField;
37 private Object FunctionField;
38 private Object NumberField;
39 private Object ObjectField;
40 private Object RangeErrorField;
41 private Object ReferenceErrorField;
42 private Object RegExpField;
43 private Object StringField;
44 private Object SyntaxErrorField;
45 private Object TypeErrorField;
46 private Object VBArrayField;
47 private Object URIErrorField;
49 // function properties
50 public new Object decodeURI;
51 public new Object decodeURIComponent;
52 public new Object encodeURI;
53 public new Object encodeURIComponent;
54 [NotRecommended ("escape")]
55 public new Object escape;
56 public new Object eval;
57 public new Object isNaN;
58 public new Object isFinite;
59 public new Object parseInt;
60 public new Object parseFloat;
61 public new Object GetObject;
62 public new Object ScriptEngine;
63 public new Object ScriptEngineBuildVersion;
64 public new Object ScriptEngineMajorVersion;
65 public new Object ScriptEngineMinorVersion;
66 [NotRecommended ("unescape")]
67 public new Object unescape;
68 // built-in types
69 public new Object boolean;
70 public new Object @byte;
71 public new Object @char;
72 public new Object @decimal;
73 public new Object @double;
74 public new Object @float;
75 public new Object @int;
76 public new Object @long;
77 public new Object @sbyte;
78 public new Object @short;
79 public new Object @void;
80 public new Object @uint;
81 public new Object @ulong;
82 public new Object @ushort;
84 //backing fields for private properties used to initialize orignalXXX properties
85 private LenientArrayPrototype arrayPrototypeField;
86 private LenientFunctionPrototype functionPrototypeField;
87 private LenientObjectPrototype objectPrototypeField;
88 private VsaEngine engine;
90 internal LenientGlobalObject(VsaEngine engine){
91 this.engine = engine;
93 this.Infinity = Double.PositiveInfinity;
94 this.NaN = Double.NaN;
95 this.undefined = null;
97 this.ActiveXObjectField = Missing.Value;
98 this.ArrayField = Missing.Value;
99 this.BooleanField = Missing.Value;
100 this.DateField = Missing.Value;
101 this.EnumeratorField = Missing.Value;
102 this.ErrorField = Missing.Value;
103 this.EvalErrorField = Missing.Value;
104 this.FunctionField = Missing.Value;
105 this.MathField = Missing.Value;
106 this.NumberField = Missing.Value;
107 this.ObjectField = Missing.Value;
108 this.RangeErrorField = Missing.Value;
109 this.ReferenceErrorField = Missing.Value;
110 this.RegExpField = Missing.Value;
111 this.StringField = Missing.Value;
112 this.SyntaxErrorField = Missing.Value;
113 this.TypeErrorField = Missing.Value;
114 this.VBArrayField = Missing.Value;
115 this.URIErrorField = Missing.Value;
117 Type super = typeof(GlobalObject);
118 LenientFunctionPrototype fprot = this.functionPrototype;
119 this.decodeURI = new BuiltinFunction("decodeURI", this, super.GetMethod("decodeURI"), fprot);
120 this.decodeURIComponent = new BuiltinFunction("decodeURIComponent", this, super.GetMethod("decodeURIComponent"), fprot);
121 this.encodeURI = new BuiltinFunction("encodeURI", this, super.GetMethod("encodeURI"), fprot);
122 this.encodeURIComponent = new BuiltinFunction("encodeURIComponent", this, super.GetMethod("encodeURIComponent"), fprot);
123 this.escape = new BuiltinFunction("escape", this, super.GetMethod("escape"), fprot);
124 this.eval = new BuiltinFunction("eval", this, super.GetMethod("eval"), fprot);
125 this.isNaN = new BuiltinFunction("isNaN", this, super.GetMethod("isNaN"), fprot);
126 this.isFinite = new BuiltinFunction("isFinite", this, super.GetMethod("isFinite"), fprot);
127 this.parseInt = new BuiltinFunction("parseInt", this, super.GetMethod("parseInt"), fprot);
128 this.GetObject = new BuiltinFunction("GetObject", this, super.GetMethod("GetObject"), fprot);
129 this.parseFloat = new BuiltinFunction("parseFloat", this, super.GetMethod("parseFloat"), fprot);
130 this.ScriptEngine = new BuiltinFunction("ScriptEngine", this, super.GetMethod("ScriptEngine"), fprot);
131 this.ScriptEngineBuildVersion = new BuiltinFunction("ScriptEngineBuildVersion", this, super.GetMethod("ScriptEngineBuildVersion"), fprot);
132 this.ScriptEngineMajorVersion = new BuiltinFunction("ScriptEngineMajorVersion", this, super.GetMethod("ScriptEngineMajorVersion"), fprot);
133 this.ScriptEngineMinorVersion = new BuiltinFunction("ScriptEngineMinorVersion", this, super.GetMethod("ScriptEngineMinorVersion"), fprot);
134 this.unescape = new BuiltinFunction("unescape", this, super.GetMethod("unescape"), fprot);
136 this.boolean = Typeob.Boolean;
137 this.@byte = Typeob.Byte;
138 this.@char = Typeob.Char;
139 this.@decimal = Typeob.Decimal;
140 this.@double = Typeob.Double;
141 this.@float = Typeob.Single;
142 this.@int = Typeob.Int32;
143 this.@long = Typeob.Int64;
144 this.@sbyte = Typeob.SByte;
145 this.@short = Typeob.Int16;
146 this.@void = Typeob.Void;
147 this.@uint = Typeob.UInt32;
148 this.@ulong = Typeob.UInt64;
149 this.@ushort = Typeob.UInt16;
152 private LenientArrayPrototype arrayPrototype{
153 get{
154 if (this.arrayPrototypeField == null)
155 this.arrayPrototypeField = new LenientArrayPrototype(this.functionPrototype, this.objectPrototype);
156 return this.arrayPrototypeField;
160 private LenientFunctionPrototype functionPrototype{
161 get{
162 if (this.functionPrototypeField == null){
163 Object junk = this.objectPrototype; //initialize functionPrototypeField indiretly because of circularity
165 return this.functionPrototypeField;
169 private LenientObjectPrototype objectPrototype{
170 get{
171 if (this.objectPrototypeField == null){
172 LenientObjectPrototype prototype = this.objectPrototypeField = new LenientObjectPrototype(this.engine);
173 LenientFunctionPrototype fprot = this.functionPrototypeField = new LenientFunctionPrototype(prototype);
174 prototype.Initialize(fprot);
175 JSObject prot = new JSObject(prototype, false);
176 prot.AddField("constructor").SetValue(prot, fprot);
177 fprot.proto = prot;
179 return this.objectPrototypeField;
183 internal override ActiveXObjectConstructor originalActiveXObject{
184 get{
185 if (this.originalActiveXObjectField == null)
186 this.originalActiveXObjectField = new ActiveXObjectConstructor(this.functionPrototype);
187 return this.originalActiveXObjectField;
191 internal override ArrayConstructor originalArray{
192 get{
193 if (this.originalArrayField == null)
194 this.originalArrayField = new ArrayConstructor(this.functionPrototype, this.arrayPrototype);
195 return this.originalArrayField;
199 internal override BooleanConstructor originalBoolean{
200 get{
201 if (this.originalBooleanField == null)
202 this.originalBooleanField = new BooleanConstructor(this.functionPrototype, new LenientBooleanPrototype(this.functionPrototype, this.objectPrototype));
203 return this.originalBooleanField;
207 internal override DateConstructor originalDate{
208 get{
209 if (this.originalDateField == null)
210 this.originalDateField = new LenientDateConstructor(this.functionPrototype, new LenientDatePrototype(this.functionPrototype, this.objectPrototype));
211 return this.originalDateField;
215 internal override ErrorConstructor originalError{
216 get{
217 if (this.originalErrorField == null)
218 this.originalErrorField = new ErrorConstructor(this.functionPrototype, new LenientErrorPrototype(this.functionPrototype, this.objectPrototype, "Error"), this);
219 return this.originalErrorField;
223 internal override EnumeratorConstructor originalEnumerator{
224 get{
225 if (this.originalEnumeratorField == null)
226 this.originalEnumeratorField = new EnumeratorConstructor(this.functionPrototype, new LenientEnumeratorPrototype(this.functionPrototype, this.objectPrototype));
227 return this.originalEnumeratorField;
231 internal override ErrorConstructor originalEvalError{
232 get{
233 if (this.originalEvalErrorField == null)
234 this.originalEvalErrorField = new ErrorConstructor("EvalError", ErrorType.EvalError, this.originalError, this);
235 return this.originalEvalErrorField;
239 internal override FunctionConstructor originalFunction{
240 get{
241 if (this.originalFunctionField == null)
242 this.originalFunctionField = new FunctionConstructor(this.functionPrototype);
243 return this.originalFunctionField;
247 internal override NumberConstructor originalNumber{
248 get{
249 if (this.originalNumberField == null)
250 this.originalNumberField = new NumberConstructor(this.functionPrototype, new LenientNumberPrototype(this.functionPrototype, this.objectPrototype));
251 return this.originalNumberField;
255 internal override ObjectConstructor originalObject{
256 get{
257 if (this.originalObjectField == null)
258 this.originalObjectField = new ObjectConstructor(this.functionPrototype, this.objectPrototype);
259 return this.originalObjectField;
263 internal override ObjectPrototype originalObjectPrototype{
264 get{
265 if (this.originalObjectPrototypeField == null)
266 this.originalObjectPrototypeField = ObjectPrototype.ob;
267 return this.originalObjectPrototypeField;
271 internal override ErrorConstructor originalRangeError{
272 get{
273 if (this.originalRangeErrorField == null)
274 this.originalRangeErrorField = new ErrorConstructor("RangeError", ErrorType.RangeError, this.originalError, this);
275 return this.originalRangeErrorField;
279 internal override ErrorConstructor originalReferenceError{
280 get{
281 if (this.originalReferenceErrorField == null)
282 this.originalReferenceErrorField = new ErrorConstructor("ReferenceError", ErrorType.ReferenceError, this.originalError, this);
283 return this.originalReferenceErrorField;
287 internal override RegExpConstructor originalRegExp{
288 get{
289 if (this.originalRegExpField == null)
290 this.originalRegExpField = new RegExpConstructor(this.functionPrototype, new LenientRegExpPrototype(this.functionPrototype,
291 this.objectPrototype), this.arrayPrototype);
292 return this.originalRegExpField;
296 internal override StringConstructor originalString{
297 get{
298 if (this.originalStringField == null)
299 this.originalStringField = new LenientStringConstructor(this.functionPrototype,
300 new LenientStringPrototype(this.functionPrototype, this.objectPrototype));
301 return this.originalStringField;
305 internal override ErrorConstructor originalSyntaxError{
306 get{
307 if (this.originalSyntaxErrorField == null)
308 this.originalSyntaxErrorField = new ErrorConstructor("SyntaxError", ErrorType.SyntaxError, this.originalError, this);
309 return this.originalSyntaxErrorField;
313 internal override ErrorConstructor originalTypeError{
314 get{
315 if (this.originalTypeErrorField == null)
316 this.originalTypeErrorField = new ErrorConstructor("TypeError", ErrorType.TypeError, this.originalError, this);
317 return this.originalTypeErrorField;
321 internal override ErrorConstructor originalURIError{
322 get{
323 if (this.originalURIErrorField == null)
324 this.originalURIErrorField = new ErrorConstructor("URIError", ErrorType.URIError, this.originalError, this);
325 return this.originalURIErrorField;
329 internal override VBArrayConstructor originalVBArray{
330 get{
331 if (this.originalVBArrayField == null)
332 this.originalVBArrayField = new VBArrayConstructor(this.functionPrototype,
333 new LenientVBArrayPrototype(this.functionPrototype, this.objectPrototype));
334 return this.originalVBArrayField;
338 new public Object ActiveXObject{
339 get{
340 if (this.ActiveXObjectField is Missing)
341 this.ActiveXObjectField = this.originalActiveXObject;
342 return this.ActiveXObjectField;
344 set{
345 this.ActiveXObjectField = value;
349 new public Object Array{
350 get{
351 if (this.ArrayField is Missing)
352 this.ArrayField = this.originalArray;
353 return this.ArrayField;
355 set{
356 this.ArrayField = value;
360 new public Object Boolean{
361 get{
362 if (this.BooleanField is Missing)
363 this.BooleanField = this.originalBoolean;
364 return this.BooleanField;
366 set{
367 this.BooleanField = value;
371 new public Object Date{
372 get{
373 if (this.DateField is Missing)
374 this.DateField = this.originalDate;
375 return this.DateField;
377 set{
378 this.DateField = value;
382 new public Object Enumerator{
383 get{
384 if (this.EnumeratorField is Missing)
385 this.EnumeratorField = this.originalEnumerator;
386 return this.EnumeratorField;
388 set{
389 this.EnumeratorField = value;
393 new public Object Error{
394 get{
395 if (this.ErrorField is Missing)
396 this.ErrorField = this.originalError;
397 return this.ErrorField;
399 set{
400 this.ErrorField = value;
404 new public Object EvalError{
405 get{
406 if (this.EvalErrorField is Missing)
407 this.EvalErrorField = this.originalEvalError;
408 return this.EvalErrorField;
410 set{
411 this.EvalErrorField = value;
415 new public Object Function{
416 get{
417 if (this.FunctionField is Missing)
418 this.FunctionField = this.originalFunction;
419 return this.FunctionField;
421 set{
422 this.FunctionField = value;
426 new public Object Math{
427 get{
428 if (this.MathField is Missing)
429 this.MathField = new LenientMathObject(this.objectPrototype, this.functionPrototype);
430 return this.MathField;
432 set{
433 this.MathField = value;
437 new public Object Number{
438 get{
439 if (this.NumberField is Missing)
440 this.NumberField = this.originalNumber;
441 return this.NumberField;
443 set{
444 this.NumberField = value;
448 new public Object Object{
449 get{
450 if (this.ObjectField is Missing)
451 this.ObjectField = this.originalObject;
452 return this.ObjectField;
454 set{
455 this.ObjectField = value;
459 new public Object RangeError{
460 get{
461 if (this.RangeErrorField is Missing)
462 this.RangeErrorField = this.originalRangeError;
463 return this.RangeErrorField;
465 set{
466 this.RangeErrorField = value;
470 new public Object ReferenceError{
471 get{
472 if (this.ReferenceErrorField is Missing)
473 this.ReferenceErrorField = this.originalReferenceError;
474 return this.ReferenceErrorField;
476 set{
477 this.ReferenceErrorField = value;
481 new public Object RegExp{
482 get{
483 if (this.RegExpField is Missing)
484 this.RegExpField = this.originalRegExp;
485 return this.RegExpField;
487 set{
488 this.RegExpField = value;
492 new public Object String{
493 get{
494 if (this.StringField is Missing)
495 this.StringField = this.originalString;
496 return this.StringField;
498 set{
499 this.StringField = value;
503 new public Object SyntaxError{
504 get{
505 if (this.SyntaxErrorField is Missing)
506 this.SyntaxErrorField = this.originalSyntaxError;
507 return this.SyntaxErrorField;
509 set{
510 this.SyntaxErrorField = value;
514 new public Object TypeError{
515 get{
516 if (this.TypeErrorField is Missing)
517 this.TypeErrorField = this.originalTypeError;
518 return this.TypeErrorField;
520 set{
521 this.TypeErrorField = value;
525 new public Object URIError{
526 get{
527 if (this.URIErrorField is Missing)
528 this.URIErrorField = this.originalURIError;
529 return this.URIErrorField;
531 set{
532 this.URIErrorField = value;
536 new public Object VBArray{
537 get{
538 if (this.VBArrayField is Missing)
539 this.VBArrayField = this.originalVBArray;
540 return this.VBArrayField;
542 set{
543 this.VBArrayField = value;